<!--计算电费-->
<div class="modal fade" id="jisuanshuifei" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">计算水费</h4>
      </div>
      <div class="modal-body">
          <form id="myform2">
              
      <div class="form-group input-group col-md-12">
         <span class="input-group-addon">上个月水费吨数</span>
         <input type="text"  class="form-control" readonly="readonly"  name="predunshu" placeholder="上个月水费吨数">
      </div>
              
           <div class="form-group input-group col-md-12">
         <span class="input-group-addon">这个月水费吨数</span>
         <input type="text"  class="form-control"   name="dunshu" placeholder="水费吨数">
      </div>
              
      <div class="form-group input-group col-md-12">
         <span class="input-group-addon">每吨价格</span>
         <input type="text"  class="form-control"   name="dunshujiage" value="<{$shui_fare}>" placeholder="每吨价格">
      </div>
              
              
          </form>
          
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success" id="btnjisuanshuifei">计算</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>
<!--end计算电费-->
<script>
    $('#jisuanshuifei').on('show.bs.modal', function (event){
    var button = $(event.relatedTarget);
    
    var inputname=button.data("inputname");
    if(inputname){
    $("#btnjisuanshuifei").data("inputname",inputname);
    }
    $("input[name='predunshu']").val($("input[name='preshui_du']").val());
    $("input[name='dunshu']").val($("input[name='shui_du']").val());

});
$('#jisuanshuifei').on('hidden.bs.modal', function (e) {
    var inputname=$("#btnjisuanshuifei").data("inputname");
    if(inputname){
    $("input[name='"+inputname+"']").focus();
}
});

$("#btnjisuanshuifei").click(function(){
        var dunshu=$("input[name='dunshu']").val();
        var predunshu=$("input[name='predunshu']").val();
        var inputname=$(this).data("inputname");
        var dunshujiage=$("input[name='dunshujiage']").val();
        if(isNaN(dunshu)){
            alert("水费吨数请输入数字");
        }
        if(isNaN(dunshujiage)){
            alert("每吨价格请输入数字");
        }
        var zj=(dunshu-predunshu)*dunshujiage;
        $("input[name='"+inputname+"']").val(zj.toFixed(2));
        $("#jisuanshuifei").modal('hide');
        $("input[name='"+inputname+"']").focus();
    });
    $("input[name='dunshu']").blur(function(){
        $("input[name='shui_du']").val($(this).val());
    }); 
</script>